package com.le.tester.imooc.masterJUC.lookforconcurrency;

/**
 * createTime：2022/1/28 14:20
 * description：多种线程
 * 1.运行结果出错（计数不准确，具体出错的位置）
 */
public class MultiThreadsError implements Runnable {

    static MultiThreadsError instance = new MultiThreadsError();
    final boolean[] marked = new boolean[100000];
    int index = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(instance);
        Thread t2 = new Thread(instance);
        Thread t3 = new Thread(instance);
        t1.start();
        t2.start();
        t3.start();
        //等待主线程
        t1.join();
        t2.join();
        t3.join();
        System.out.println("表面上的结果是：" + instance.index);
    }

    @Override
    public void run() {
//        while (index < 10000) {
//            index++;
//        }
        for (int i = 0; i < 10000; i++) {
            index++;
        }
    }
}
